<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="com.infomanage.po.*"%>
<%@page import="com.infomanage.vo.*"%>
<%@page import="com.infomanage.enums.*"%>
<%@page import="com.infomanage.service.equmgmt.*"%>
<%@page import="org.hibernate.*"%>
<%@page import="org.hibernate.cfg.*"%>
<%
	request.setCharacterEncoding("UTF-8");
	List<EquipmentManageItem> eqmts = EquipmentManageService.search(
			request, response, out);
	int count = 0;
	if (eqmts != null) {
		count = eqmts.size();
	}

	// 主界面中查询条件
	String owndeptId = request.getParameter("owndeptId");
	if (owndeptId == null)
		owndeptId = "";
	String name = request.getParameter("name");
	System.out.println("equipment name is:" + name);
	if (name == null)
		name = "";
	String state = request.getParameter("state");
	if (state == null)
		state = "";

	// 当前页号
	String currPageNum = request.getParameter("currPageNum");
	if (currPageNum == null)
		currPageNum = "1";

	// 总总页数
	int totalPageSize = EquipmentManageService.getPageCount(request,
			response, out);
	if (name != null) {
		for(int i=0;i<eqmts.size();i++){
			eqmts.clear();
		}
		SessionFactory sf = new Configuration().configure()
		.buildSessionFactory();
		Session session1 = sf.openSession();
		String Hql = "FROM EquipmentManage where name like '%" + name + "%'";
		System.out.println("Hql=" + Hql);
		Query q = session1.createQuery(Hql);

		List list = q.list();
		System.out.println("list size is:" + list.size());
		for (ListIterator iterator = list.listIterator(); iterator
		.hasNext();) {
			EquipmentManage equipmentManage = (EquipmentManage) iterator.next();
			int personid = equipmentManage.getPersonId();
			int equipmentOwndeptId = equipmentManage.getOwndeptId();
			int equipmentUsedeptId = equipmentManage.getUsedeptId();
			//查询人员
			String Hql1 = "From Person where personId='" + personid
			+ "'";
			System.out.println("Hql1=" + Hql1);
			Query q1 = session1.createQuery(Hql1);
			List list1 = q1.list();
			Person person = (Person) list1.get(0);
			//查询equipmentOwndeptId
			String Hql2 = "From Department where deptId='"
			+ equipmentOwndeptId + "'";
			Query q2 = session1.createQuery(Hql2);
			List list2 = q2.list();
			Department Owndept = (Department) list2.get(0);
			//查询equipmentUsedeptId
			String Hql3 = "From Department where deptId='"
			+ equipmentUsedeptId + "'";
			Query q3 = session1.createQuery(Hql3);
			List list3 = q3.list();
			Department Usedept = (Department) list3.get(0);

			EquipmentManageItem equipmentManageItem = new EquipmentManageItem();
			equipmentManageItem.setOwndept(Owndept);
			equipmentManageItem.setUsedept(Usedept);
			equipmentManageItem.setPerson(person);
			equipmentManageItem.setBean(equipmentManage);
			eqmts.add(equipmentManageItem);
			System.out.println("person name is:" + person.getName());
		}
		session1.close();
		
		
	}
	
%>
<html>
	<head>
		<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
		<link href="../../css/style.css" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="../../js/common.js"></script>
		<script type="text/javascript">
		function modifyItem(id) {
			var url = "equmgmt_edit.jsp?eqmtId=" + id;
			var width = '550px';
			var height ='500px';
			var arg = "dialogHeight:" + height + ";dialogWidth:" + width + ";status:no;location:no;";
			var returnValue = window.showModalDialog(url, "", arg);
			if(returnValue != null){
				window.location.reload();
			}
		}

		function delItem(id) {
			if(window.confirm("确定删除吗？")){
				actionFrame.location.href = "equmgmt_action.jsp?actionType=del&eqmtId=" + id;
			}
		}

		function viewItem(id){
			var url = "equmgmt_view.jsp?eqmtId=" + id;
			var width = '550px';
			var height ='500px';
			var arg = "dialogHeight:" + height + ";dialogWidth:" + width + ";status:no;location:no;";
			var returnValue = window.showModalDialog(url, "", arg);
		}

	   function showError(error){
		   alert(error);
	   }

	   function showInfo(info){
		   if(info && info != "") {
		   		alert(info);
		   }
		   window.location.reload();
	   }
	</script>
	</head>
	<body rightmargin="0" bottommargin="0" leftmargin="0" topmargin="0"
		onclick="parent.clickBody();">
		<table width="100%" height="100%" border="0" align="center"
			cellpadding="0" cellspacing="0"
			style="table-layout: fixed; background: #ffffff;">
			<tr height="29px">
				<td valign="middle" height="29px" class="td_title"
					style="padding-left: 20px; border-right: 1px #a3c6e2 solid;">
					装备管理
				</td>
			</tr>
			<tr>
				<td valign="top">
					<table width="100%" height="100%" border="0" cellpadding="0"
						cellspacing="0" class="tabMain">
						<col width="4%">
						<col width="11%">
						<col width="10%">
						<col width="10%">
						<col width="9%">
						<col width="9%">
						<col width="9%">
						<col width="9%">
						<col width="9%">
						<col width="20%">
						<tr class="thlist">
							<td>
								<a href="#" flag="none" onclick="selectAll(this, '<%=count%>');"
									title="全选/全清" style="color: #15428B;">选择</a>
							</td>
							<td>
								名称
							</td>
							<td>
								所属单位
							</td>
							<td>
								使用单位
							</td>
							<td>
								负责人
							</td>
							<td>
								数量
							</td>
							<td>
								型号
							</td>
							<td>
								用途
							</td>
							<td>
								状态
							</td>
							<td>
								操作
							</td>
						</tr>

						<!-- 输出数据 -->
						<tr valign="top">
							<td colspan="10" width="100%">
								<div style="width: 100%; height: 100%; overflow: auto;">
									<table width="100%" class="altColorTable" cellpadding="0"
										cellspacing="0">
										<col width="4%">
										<col width="11%">
										<col width="10%">
										<col width="10%">
										<col width="9%">
										<col width="9%">
										<col width="9%">
										<col width="9%">
										<col width="9%">
										<col width="20%">
										<%
											int i = -1;
											if (eqmts != null) {
												for (EquipmentManageItem eqmt : eqmts) {
													i++;
										%>
										<tr class="tdlist">
											<td>
												<input onclick="selectItem(this);" id="selBox_<%=i%>"
													type="checkbox"
													value="<%=eqmt.getBean().getEquipmentManageId()%>">
											</td>
											<td>
												<%=eqmt.getBean().getName()%>
											</td>
											<td>
												<%=eqmt.getOwndept().getPath()%>
											</td>
											<td>
												<%=eqmt.getUsedept().getPath()%>
											</td>
											<td>
												<%=eqmt.getPerson().getName()%>
											</td>
											<td>
												<%=eqmt.getBean().getQuantity()%>
											</td>
											<td>
												<%=eqmt.getBean().getType()%>
											</td>
											<td>
												<%=eqmt.getBean().getPurpose()%>
											</td>
											<td>
												<%=DeviceStatusType.valueOf(
									eqmt.getBean().getState()).title()%>
											</td>
											<td>
												<a
													href="javascript:viewItem('<%=eqmt.getBean().getEquipmentManageId()%>');"
													title="查看详情"><img src="../../img/btn_view.png"
														border="0">&nbsp;查看</a>
												<a
													href="javascript:modifyItem('<%=eqmt.getBean().getEquipmentManageId()%>');"
													title="修改"><img src="../../img/dot_xg.gif" border="0">&nbsp;修改</a>
												<a
													href="javascript:delItem('<%=eqmt.getBean().getEquipmentManageId()%>');"
													title="删除"><img src="../../img/dot_sc.gif" border="0">&nbsp;删除</a>
											</td>
										</tr>

										<%
											}
											}
										%>
									</table>
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr>

			<!-- 分页 -->
			<tr height="20px">
				<td class="tabMainBot">
					<jsp:include page="../common/pagination.jsp" flush="true">
						<jsp:param name="totalPageSize" value="<%=totalPageSize%>" />
						<jsp:param name="currPageNum" value="<%=currPageNum%>" />
					</jsp:include>
				</td>
			</tr>
		</table>
		<iframe src="#" name="actionFrame" style="display: none;"></iframe>

		<!-- 分页表单 -->
		<form name="pageForm" action="">
			<input type="hidden" name="currPageNum" value="<%=currPageNum%>">
			<input type="hidden" name="totalPageSize" value="<%=totalPageSize%>">
			<!-- 查询参数 -->
			<input type="hidden" name="owndeptId" value="<%=owndeptId%>">
			<input type="hidden" name="name" value="<%=name%>">
			<input type="hidden" name="state" value="<%=state%>">
		</form>
	</body>
</html>
